<?php 

class ApiController extends SCController {

	public function __construct() {
		parent::__construct();
	}

	/**
	 * 获取每天的背景图url
	 * 从第三方网站抓取
	 */
	public function background($from = 'lofter') {
		switch($from) {
			case 'lofter' :
				$url = 'http://www.lofter.com/';
				$pattern = '/\{imageUrl:\'(.*)\'/iU';
			break;
			case 'bing':
				$url = 'http://cn.bing.com/';
				$pattern = '/url:\'(.*)\'/iU';
			break;
		}
		
		$matches = array();
		preg_match($pattern, file_get_contents($url), $matches);
		
		echo $matches[1];
	}
	
	/**
	 * 获取当前第三方用户开放信息
	 */
	public function openInfo($vendor) {
		switch($vendor) {
			case 'tencent' :
				$tencent = new Tencent; 
				$open_id = $tencent->openId();
				if($open_id) {
					$info = SCScabish::model('tencent')->from('sc_tencent')->where('open_id = "'.$open_id.'"')->findOne();
					$this->ajaxSuccess($info);
				} else {
					$this->ajaxFail();
				}
				
		}
	}
	
	public function __empty() {
		
	}

}